const int analogInPin = A0; 
int led = 9;          
int brightness = 255;  

void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

short int convert_adc2temperature(
   short int ax,
   short int a0,short int a1,
   short int temp0,short int temp1)
{
   short int tempx;
   tempx = temp0+(ax-a0)*(temp1-temp0)/(a1-a0);
   return tempx;
}

void loop() {
  int ax,tx;
  int fadeAmount;
  ax = analogRead(analogInPin);
  tx = convert_adc2temperature(ax,585,330,10,60);
  brightness = 255 - fadeAmount*2;
  analogWrite(led, brightness);
  delay(500);
}


